package com.summer.study.leetcode.algorithm;

import com.summer.study.leetcode.tree.*;

/**
 * @auther: 杨杰
 * @date: 2019/7/31 10:36
 * @description: 二叉树的层次遍历
 * https://leetcode-cn.com/problems/binary-tree-level-order-traversal/
 */
public class Demo102 {

    public static void main(String[] args) {
        Tree<Integer> tree = new BinaryTree<>();
        TreeUtil.createIntegerTreeNodes(tree);
        tree.levelOrder().stream().forEach(integerNode -> {
            System.out.println(integerNode);
        });
    }

    /*
    public List<List<Integer>> levelOrder(TreeNode root) {
        List<List<Integer>> levels = new ArrayList<>();
        if (root == null) return levels;
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        while (!queue.isEmpty()) {
            int level_length = queue.size();
            List<Integer> currentLevel=new ArrayList<>();
            for (int i = 0; i < level_length; ++i) {
                TreeNode node = queue.remove();
                currentLevel.add(node.val);
                if (node.left != null) queue.add(node.left);
                if (node.right != null) queue.add(node.right);
            }
            levels.add(currentLevel);
        }
        return levels;
    }
    */

}
